<!--
 * @Author: byron
 * @Date: 2021-08-26 21:14:30
 * @LastEditTime: 2021-08-31 17:43:08
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 创建一个Person类
        class Person {
            // 构造器方法
            constructor(name, age) {
                this.name = name;
                this.age = age;
            }
            // speak方法放在类的原型对象上，供实例使用
            speak() {
                console.log(`我叫${this.name},${this.age}岁`);
            }
        }
        //创建一个Student类，继承于Person
        class Student extends Person {
            constructor(name, age, grade) {
                super(name, age)
                this.grade = grade
            }
            speak() {
                console.log(`我叫${this.name},${this.age}岁,${this.grade}`);
            }
            // 类中直接出现赋值语句是给类实例增加一个属性
            a = 10
            // 前面加个static即为加个类本身，可以通过 Student.b 获取
            static b = 100
        }

        class Dog {}
        //创建类实例
        const p1 = new Person('tom', 17)
        const s1 = new Student('peter', 27, '高三')

        console.log(p1);
        console.log(s1);
        console.log(s1.a);
        console.log(Student.b);
        p1.speak()
        s1.speak()
    </script>
</body>

</html>